package question;

import track.TriathlonTrack;
import athlete.Athlete;

public class AthleteRunnable implements Runnable, Comparable<AthleteRunnable> {
	private Athlete athlete;
	private TriathlonTrack track;
	
	private int cyclingTime;
	private int runningTime;
	private int swimmingTime;
	private int totalTime;
	
	public AthleteRunnable(Athlete athlete, TriathlonTrack track) {
		this.athlete = athlete;
		this.track = track;
	}
	
	@Override
	public void run() {
		runningTime = athlete.run(track.runningSection.getSectionLength());
		cyclingTime = athlete.cycle(track.cyclingSection.getSectionLength());
		swimmingTime = athlete.swim(track.swimmingSection.getSectionLength());
		totalTime = runningTime + cyclingTime + swimmingTime;
	}

	
	public String getAthleteName(){
		return athlete.name;
	}
	public int getRunningTime(){
		return runningTime;
	}
	public int getCyclingTime(){
		return cyclingTime;
	}
	public int getSwimmingTime(){
		return swimmingTime;
	}
	public int getTotalTime(){
		return totalTime;
	}

	@Override
	public int compareTo(AthleteRunnable otherRunnable) {
		return (this.totalTime - otherRunnable.totalTime);
	}
}
